process.env.NODE_ENV = 'dev';
/*************引入模块*****************/
const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin');
const portfinder = require('portfinder');
const opn=require('opn');
const base=require('./base.js');
const path=require('path');
const conf=require('../conf.js');
const merge=require("webpack-merge");


/*************定义变量*****************/
var openBom=conf.dev.openBom;
var entry=conf.entry;
var compiler=merge(base,{
	devServer:{
	    clientLogLevel: 'warning',
	    historyApiFallback: true,
	    hot: true,
	    compress: true,
	    host: 'localhost',
	    port: 8080,
	    open: false,
	    inline:true,
	    overlay: {
	      warnings: false,
	      errors: true
	    },
	    contentBase: path.resolve(__dirname, '../../src'),
	    quiet: true // necessary for FriendlyErrorsPlugin
	}
})
/**************输出接口****************/

module.exports=new Promise((resolve, reject) => {
	portfinder.basePort = process.env.PORT || 8080;
	portfinder.getPort((err, port) => {
		if (err) {
	      reject(err)
	   } else {
	    	process.env.PORT = port
	    	compiler.devServer.port = port
	    	compiler.plugins.push(new FriendlyErrorsPlugin({
		      compilationSuccessInfo: {
		        messages: [`Your application is running here: http://${compiler.devServer.host}:${port}`],
		      },
		      onErrors:void(0)
		    }))
	    	process.env.PORT = port
	    	var uri = 'http://localhost:' + port;
	    	openBom&&opn(uri)
	    	resolve(compiler)
	    }
	})
})